<?php
/** 
 * BOOTLOADER
 *
 * @package Agregalo
 */

// No direct access
defined( "__DEENZO__" ) or die( "deenzo$" );

// Loading dependencies
bin( "exec" ) or kill( "exec$" );

// Setting up Default Charset
header("Content-type: text/html;charset=" . __LC_CTYPE__ );

function bootstrap() {

    /** Registering IS_%% information functions  */
    $exec = sql( "exec.[ sh, func ]", "-lo" );
    
    foreach ( (array) $exec as $e ) {
		is_function( $e->func, "is_page" );
		
		is_function( basename( $e->sh ), "is_page" );
    }   
    
    // Registering IS_HOME and IS_404 functions
    is_function( "home, 404", "is_page" );
            
    $exec = do_url();
    
    if ( is_object( $exec ) && sh( $exec->sh, "-ef" ) ) {
        
        // Get SH and FUNC name for local register
        $sh   = basename( $exec->sh );
	    
	    $func = sql( "exec.[ func ].( e = '$exec->e' )" );
	    
	    define( "__X11__", "$sh." . str_replace( ".", "_", $func ) );
        
        // Loading theme functions and lauching SH
        X11( "functions" ); sh( $exec->sh, "-of" );
        
		// If functions defined, calling it with AGRV
        if ( $exec->func ) 
            eval( "$exec->func( $exec->argv );" );    
	
	}
	
	// Displaying HOME or 404 Error Document
	if ( $exec === 0 )
	    define( "__X11__", "home" );
	
	elseif ( $exec == -1 )
	    define( "__X11__", "404" );
	
	// Redirect to logical DocumentRoot
	elseif ( $exec == -2 ) {	
		header( "HTTP/1.1 301 Moved Permanently" );
		header( "Location: " . sysconfig("siteurl") );
	
	// Request was received from a non equal DocumentRoot
	} elseif ( $exec == -3 ) {
	    header( "Location: " . sysconfig("siteurl") . __URI__ );
	}
	    
    
    // Loading Functions and current template
    X11( "functions" );  X11();

}